﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webadmin_pages_cp_changeInfo : System.Web.UI.Page
{
    private DataTable checkInfo;
    public string mo_ta = "";
    public string sMessage;
    public string sMessageOk;
    private Common t = new Common();
    public string tai_khoan = "";
    public string ten_hien_thi = "";

    protected void Button1_Click(object sender, EventArgs e)
    {
        string sqlString = "";
        this.sMessageOk = null;
        this.sMessage = "";
        try
        {
            if (string.IsNullOrEmpty(base.Request.Params["txtTaiKhoan"]) || string.IsNullOrEmpty(base.Request.Params["txtTenHienThi"]))
            {
                this.sMessage = "C\x00e1c th\x00e0nh phần c\x00f3 dấu (*) kh\x00f4ng được để rỗng!";
            }
            else
            {
                if (base.Request.Params["txtTaiKhoan"].ToString() != this.Session["tai_khoan"].ToString())
                {
                    sqlString = "select tai_khoan from PhanQuyen_nguoi_dung where tai_khoan='" + this.t.TextFormat(base.Request.Params["txtTaiKhoan"].ToString()) + "'";
                    this.checkInfo = this.t.getDataTable(sqlString);
                    if (this.checkInfo.Rows.Count > 0)
                    {
                        this.sMessage = "T\x00e0i khoản n\x00e0y đ\x00e3 được đăng k\x00fd, bạn h\x00e3y chọn lại t\x00e0i khoản kh\x00e1c!";
                        return;
                    }
                }
                sqlString = string.Concat(new object[] { "update PhanQuyen_nguoi_dung set tai_khoan='", this.t.TextFormat(base.Request.Params["txtTaiKhoan"].ToString().Trim()), "',ten_hien_thi=N'", this.t.TextFormat(base.Request.Params["txtTenHienThi"].ToString().Trim()), "',mo_ta=N'", this.t.TextFormat(base.Request.Params["txtMoTa"].ToString().Trim()), "' where ma_nguoi_dung=", this.Session["UserID"] });
                new Common().execNoneQuery(sqlString);
                this.sMessageOk = "Đ\x00e3 thay đổi th\x00f4ng tin th\x00e0nh c\x00f4ng!";
                this.Session["tai_khoan"] = this.t.TextFormat(base.Request.Params["txtTaiKhoan"].ToString());
                this.Session["ten_hien_thi"] = this.t.TextFormat(base.Request.Params["txtTenHienThi"].ToString());
                this.tai_khoan = this.Session["tai_khoan"].ToString();
                this.ten_hien_thi = this.Session["ten_hien_thi"].ToString();
            }
        }
        catch (Exception exception)
        {
            this.sMessage = exception.Message;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        base.Title = "Thay doi thong tin tai khoan";
        if (this.Session["UserID"] == null)
        {
            base.Response.Redirect("cp_login.aspx");
        }
        this.checkInfo = this.t.getDataTable("select tai_khoan,ten_hien_thi,mo_ta from PhanQuyen_nguoi_dung where ma_nguoi_dung=" + this.Session["UserID"]);
        this.tai_khoan = this.checkInfo.Rows[0][0].ToString();
        this.ten_hien_thi = this.checkInfo.Rows[0][1].ToString();
        this.mo_ta = this.checkInfo.Rows[0][2].ToString();
    }
}
